<?php
/**
 * ws服务器
 * User: wyj
 * Date: 2018/1/26
 * Time: 9:36
 */

namespace Core;


class Browers extends \Swoole\WebSocket\Server
{
    /**
     * 构造方法
     * @param string $ip 绑定IP
     * @param int $port 监听端口
     */
    public function __construct($ip,$port)
    {
        parent::__construct($ip, $port);
    }

    /**
     * 启动服务
     * @param $handler
     * @param array $config
     */
    public function run($handler,  array $config)
    {
        $this->set($config);
        $this->on('Start', array($handler, 'onStart'));
        $this->on('ManagerStart', array($handler, 'onManagerStart'));
        $this->on('WorkerStart', array($handler, 'onWorkerStart'));
        $this->on('WorkerError', array($handler, 'onWorkerError'));
        $this->on('WorkerExit', array($handler, 'onWorkerExit'));
        $this->on('WorkerStop', array($handler, 'onWorkerStop'));
        $this->on('Open', array($handler, 'onOpen'));
        $this->on('Message', array($handler, 'onMessage'));
        $this->on('Close', array($handler, 'onClose'));
        $this->on('Shutdown', array($handler, 'onShutdown'));
        $this->start();
    }
}